package buttons.view;

import java.awt.Color;

import processing.core.PApplet;
import processing.core.PFont;
import view.V_DisplayObject;
import view.DisplayList;

public class V_Button extends V_DisplayObject
{
  protected String name;
  protected int transp = 255;
  protected int offset = 0;  // used to adjust the color when mouseOver or mousePressed while staying in the same hue.

  // create a button with the given name and a width/height
  public V_Button(String n, float xWidth, float yHeight)
  {
    name = n;
    xSize = xWidth;
    ySize = yHeight;
    this.setBGColor(new Color(220, 220, 220));
  }
  
  @Override
  public void display(PApplet p)
  {
    if(visible)
    { 
      //TODO: bgColor >> 16 & 0xFF, bgColor >> 8 & 0xFF, bgColor & 0xFF, bgColor >> 24 & 0xFF
      int tmpColor = p.color(p.red(bgColor)+offset, p.green(bgColor)+offset, p.blue(bgColor)+offset, transp); 
      p.stroke(0,0,0,transp);
      p.strokeWeight(1);
      p.fill(tmpColor);    
      p.rect(xLoc, yLoc, xSize, ySize);
    }
  }
  
  // set the offset color value for mouse overs and mouse pressed
  public void setOffset(int val)
  {
    offset = val;
  }
  
  public String getName()
  {
    return name;
  }
  
  public void setName(String n)
  {
    name = n;
  }
  
  public void setAlpha(float val)
  {
    transp = (int)val;
  }
  
  public int getAlpha()
  {
    return transp;
  }
  
  public void greyOut(boolean val)
  {
    if(val == true) setAlpha(Math.max(transp-7, 75));
    else if (val == false) setAlpha(Math.min(transp+7, 255));
  }
}